/**
 * Copyright (c) 2020 Coder League
 * All rights reserved.
 *
 * File：ApplicationInitializer.java
 * History:
 *         2020年12月19日: Initially created, Chrise.
 */
package club.coderleague.cfss.runners;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import club.coderleague.cfss.cache.CacheManager;
import club.coderleague.cfss.service.user.UserService;

/**
 * 应用程序初始化器。
 * @author Chrise
 */
@Component
public class ApplicationInitializer implements CommandLineRunner {
	private static final Logger logger = LoggerFactory.getLogger(ApplicationInitializer.class);
	
	@Autowired
	private UserService userService;
	@Autowired
	private CacheManager cacheManager;
	
	/**
	 * @see org.springframework.boot.CommandLineRunner#run(java.lang.String[])
	 */
	@Override
	public void run(String... args) throws Exception {
		try {
			// 注册管理员
			this.userService.execRegisterAdminstrator();
			
			// 初始化缓存管理器
			this.cacheManager.initialize();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
	}
}
